package galkin.id.project;

import java.util.ArrayList;
import java.util.Scanner;

public class SpaceMarineGame {
	 Scanner sc=new Scanner (System.in);
	 ScenarioParser parser;
	 boolean play=true;
	 public SpaceMarineGame(){
		 parser=new ScenarioParser();
//			parser.parseXmlFile("C:\\Users\\Student\\workspace\\Space Marine\\Scenarios.xml");
			parser.parseXmlFile("Scenarios.xml");

			parser.initilizeScenarios();
	 }
	 public void play(){
		 int id=1;
			while (play){
				id=displayScenario(id);
			}
	
			System.out.println ("thanks for playing");
			
	 }
	 public int displayScenario(int id){
		 Scenario initscenario=parser.getScenariobyId(id);
			String story=initscenario.getStory();
			System.out.println (story);
			ArrayList <ScenarioOption> scenariooption=initscenario.getOptions();
			int p=0;
			for (p=0; p<scenariooption.size(); p++) {
				String choice=scenariooption.get(p).getChoice();
				System.out.println ((p+1)+")"+choice);
			}
			int quit= (p +1);
			System.out.println(quit +") Quit game");
			System.out.println ("press a number to make a choice");
			int selection=sc.nextInt();
			
			if (selection==quit){
				play=false;
				selection =1;
			}
			selection-=1;
			return scenariooption.get(selection).getScenarioId();
	 }
	 
	 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
	 new SpaceMarineGame().play();
	}
	
}
